#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Instruments/MultiAssetOption.h>
#pragma unmanaged 
#include <ql\experimental\exoticoptions\spreadoption.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL::Instruments;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Experimental { namespace Exoticoptions {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of ISpreadOption
	public ref class CSpreadOption  : 
            public CMultiAssetOption,
            public Cephei::QL::Experimental::Exoticoptions::ISpreadOption
	{
	protected: 
		boost::shared_ptr<QuantLib::SpreadOption>* _ppSpreadOption;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::SpreadOption>* _phSpreadOption;
#endif
		Object^ _SpreadOptionOwner;     // reference to object that manages the storage for this object
	internal:
		CSpreadOption (Cephei::QL::Instruments::IPlainVanillaPayoff^ payoff, Cephei::QL::IExercise^ exercise, Cephei::QL::IPricingEngine^ QL_Pricer);
        CSpreadOption (boost::shared_ptr<QuantLib::SpreadOption>& childNative, Object^ owner);
        CSpreadOption (QuantLib::SpreadOption& childNative, Object^ owner);
        CSpreadOption (CSpreadOption^ copy);
        CSpreadOption (PLATFORM::Type^ t);
#ifdef STRUCT
        CSpreadOption (QuantLib::SpreadOption childNative);
#endif       
#ifdef HANDLE
		CSpreadOption (QuantLib::Handle<QuantLib::SpreadOption>& childNative, Object^ owner);
		CSpreadOption (QuantLib::Handle<QuantLib::SpreadOption> childNative);
#endif
		virtual ~CSpreadOption ();
		!CSpreadOption ();

	internal:
		QuantLib::SpreadOption& GetReference ();
		boost::shared_ptr<QuantLib::SpreadOption>& GetShared ();
		QuantLib::SpreadOption* GetPointer ();
        void SetSpreadOption (boost::shared_ptr<QuantLib::SpreadOption> native)
        {
            if (_ppSpreadOption != NULL)
                delete _ppSpreadOption;
            _ppSpreadOption = new boost::shared_ptr<QuantLib::SpreadOption> (native);
            SetMultiAssetOption (boost::dynamic_pointer_cast<QuantLib::MultiAssetOption> (*_ppSpreadOption));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::SpreadOption>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Experimental::Exoticoptions::ISpreadOption^>::typeid)]
	[FactoryFor(Cephei::QL::Experimental::Exoticoptions::ISpreadOption::typeid)]
	[FactoryFor(Cephei::QL::Experimental::Exoticoptions::ISpreadOption_Factory::typeid)]
	public ref class CSpreadOption_Factory sealed : public ISpreadOption_Factory
	{
	public:
        virtual ISpreadOption^ Create (Cephei::QL::Instruments::IPlainVanillaPayoff^ payoff, Cephei::QL::IExercise^ exercise, Cephei::QL::IPricingEngine^ QL_Pricer);
    };
   
/*Cephei*/ } /*QL*/ } /*Experimental*/ } /*Exoticoptions */}
